#include <climits>
#include <iostream>
#include <vector>
#include <set>
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;

int n;
int sum = INT_MAX;
int arr[11];
set<int> s;

bool isPrim(int n)
{
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}

void dfs(int k, int num)
{
    if (n == s.size())
    {
        sum = min(sum, num);
        return;
    }
    for (int i = 2; i <= arr[k]; i++)
    {
        if (arr[k] % i == 0 && isPrim(i))
        {
            int p = s.size();
            s.insert(i);
            if (s.size() > p)
            {
                dfs(k + 1, num + i);
                s.erase(i);
            }
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    dfs(0, 0);
    if (sum == INT_MAX)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << sum << endl;
    }
    return 0;
}

int n;
bool dp[1010] = { false };
int arr[11];
int ret = INT_MAX;

bool bead(int x)
{
    for (int i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
        {
            return false;
        }
    }
    return true;
}

void dfs(int pos, int sum)
{
    if (pos == n)
    {
        ret = min(ret, sum);
        return;
    }
    for (int i = 2; i <= arr[pos]; i++)
    {
        if (arr[pos] % i == 0 && bead(i) && !dp[i])
        {
            dp[i] = true;
            dfs(pos + 1, sum + i);
            dp[i] = false;
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    dfs(0, 0);
    if (ret == INT_MAX)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << ret << endl;
    return 0;
}


class Solution {
public:
    int dp[11][11] = { 0 };
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };

    int countPath(vector<vector<int> >& CityMap, int n, int m) {
        // write code here
        queue<pair<int, int>> q;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (CityMap[i][j] == 2)
                {
                    q.push({ i,j });
                }
            }
        }
        int ret = 0;
        while (q.size())
        {
            int x = q.front().first;
            int y = q.front().second;
            q.pop();
            for (int i = 0; i < 4; i++)
            {
                int x1 = x + dx[i];
                int y1 = y + dy[i];
                if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m && CityMap[x1][y1] == 0 && dp[x1][y1] == 0)
                {
                    dp[x1][y1] = dp[x][y] + 1;
                    q.push({ x1,y1 });
                }
                if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m && CityMap[x1][y1] == 1)
                {
                    if (dp[x1][y1] == 0 || dp[x1][y1] > dp[x][y] + 1)
                    {
                        dp[x1][y1] = dp[x][y] + 1;
                        ret = 0;
                    }
                    if (dp[x1][y1] == dp[x][y] + 1)
                    {
                        ret++;
                    }
                }
            }
        }
        return ret;
    }
};

class Solution {
public:

    int _n, _m;
    int x1, x2, y1, y2;
    int dist[15][15] = { 0 };
    int cnt[15][15] = { 0 };
    int dx[4] = { 0,0,-1,1 };
    int dy[4] = { -1,1,0,0 };

    int bfs(vector<vector<int> >& CityMap)
    {
        memset(dist, -1, sizeof(dist));
        queue<pair<int, int>> q;
        q.push({ x1,y1 });
        dist[x1][y1] = 0;
        cnt[x1][y1] = 1;
        while (q.size())
        {
            auto [a, b] = q.front();
            q.pop();
            for (int i = 0; i < 4; i++)
            {
                int x = a + dx[i];
                int y = b + dy[i];
                if (x >= 0 && x < _n && y >= 0 && y < _m && CityMap[x][y] != -1)
                {
                    if (dist[x][y] == -1)
                    {
                        dist[x][y] = dist[a][b] + 1;
                        cnt[x][y] = cnt[a][b];
                        q.push({ x,y });
                    }
                    else
                    {
                        if (dist[a][b] + 1 == dist[x][y])
                        {
                            cnt[x][y] += cnt[a][b];
                        }
                    }
                }
            }
        }
        return cnt[x2][y2];
    }

    int countPath(vector<vector<int> >& CityMap, int n, int m) {
        // write code here
        _n = n;
        _m = m;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (CityMap[i][j] == 1)
                {
                    x1 = i;
                    y1 = j;
                }
                if (CityMap[i][j] == 2)
                {
                    x2 = i;
                    y2 = j;
                }
            }
        }
        return bfs(CityMap);
    }
};